package cn.com.chengmandian.bike.service.impl;

import cn.com.chengmandian.bike.dto.FaultAdviceAddForm;
import cn.com.chengmandian.bike.dto.FaultAdviceDto;
import cn.com.chengmandian.bike.mapper.EbFaultAdviceMapper;
import cn.com.chengmandian.bike.model.EbFaultAdvice;
import cn.com.chengmandian.bike.model.vo.FaultAdviceVo;
import cn.com.chengmandian.bike.service.IEbFaultAdviceService;
import cn.com.chengmandian.bike.service.IEbMessageInfoService;
import cn.com.chengmandian.core.common.constants.CommonConstant;
import cn.com.chengmandian.core.common.utils.BillNoUtil;
import cn.com.chengmandian.core.web.pojo.AgentUser;
import cn.com.chengmandian.service.bike.constants.MessageBusinessTypeEnum;
import cn.com.chengmandian.service.bike.constants.MessageChannelEnum;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 电单车运营-意见反馈 服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2021-12-23
 */
@Service
public class EbFaultAdviceServiceImpl extends ServiceImpl<EbFaultAdviceMapper, EbFaultAdvice> implements IEbFaultAdviceService {

    @Autowired
    private IEbMessageInfoService messageInfoService;

    @Override
    public void addAdvice(FaultAdviceAddForm faultAdviceForm, AgentUser agentUser) {
        EbFaultAdvice faultAdvice = new EbFaultAdvice();
        faultAdvice.setNo(BillNoUtil.getSimpleNo("FA-"));
        faultAdvice.setAreaId(faultAdviceForm.getAreaId());
        faultAdvice.setMemberId(agentUser.getId());
        faultAdvice.setContent(faultAdviceForm.getContent());
        faultAdvice.setImgUrl(faultAdviceForm.getImgUrl());
        faultAdvice.setStatus(CommonConstant.ZERO);
        faultAdvice.setType(faultAdviceForm.getType());
        this.save(faultAdvice);

        messageInfoService.addSys(agentUser.getId(), MessageChannelEnum.SYS,
                "尊敬的用户您好，已收到您的意见反馈内容（编号："+faultAdvice.getNo()+"），我们将尽快安排处理并给予回复，请耐心等待",
                null, MessageBusinessTypeEnum.ADVICE, faultAdvice.getId());
    }

    @Override
    public IPage<FaultAdviceVo> getPage(FaultAdviceDto dto) {
        Page page = Page.of(dto.getPageNumber(), dto.getPageSize());
        return baseMapper.getPage(page, dto);
    }

    @Override
    public FaultAdviceVo detail(Integer id) {
        return baseMapper.detail(id);
    }
}
